<template>
	<section v-loading="listLoading">
		<!--列表-->
		<el-table :data="users" border stripe highlight-current-row style="width: 100%;">
            <el-table-column prop="name" label="姓名" min-width="60" align="center">
			</el-table-column>
			<el-table-column prop="phone" label="电话" min-width="60" align="center">
			</el-table-column>
			<el-table-column prop="address" label="地址" min-width="60" align="center">
			</el-table-column>
			<el-table-column prop="remarks" label="备注" min-width="60" align="center">
			</el-table-column>
			<el-table-column label="操作" width="120" align="center">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
				</template>
			</el-table-column>
		</el-table>
        <!--编辑界面-->
		<el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false" width="800px">
			<el-form :model="editForm" label-width="80px" ref="editForm">
				<el-form-item label="姓名" prop="name">
                    <el-input v-model="editForm.name"/>
                </el-form-item>
                <el-form-item label="电话" prop="phone">
                    <el-input v-model="editForm.phone"/>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                   <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="editForm.address"></el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remarks">
                    <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="editForm.remarks"></el-input>
                </el-form-item>
				
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="mini" @click.native="editFormVisible = false">取消</el-button>
				<el-button size="mini" type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>
	</section>
</template>
<script>
	export default {
		data() {
			return {
				users: [],
				listLoading: false,
				editFormVisible: false,
				editLoading: false,
				editForm: {
					name: '',
                    phone: '',
                    address:'',
                    remarks:''
				},
			}
		},
		methods: {
			
		    
			getUsers:function (){
				this.listLoading = true;
				let para = {
					
				};
				var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','admin_five_palace_token':JSON.parse(sessionStorage.getItem('token'))},
				});  
				instance.post('admin/platform/manage/getReturnAdress', this.qs.stringify(para)).then(data => {
					let  res = data.data;
					console.log(data);
					if (res.code !== 0) {
						this.$message({
							message: res.msg,
							type: 'error'
						});
					} else {
						this.users = []
						this.users.push(res.data);
						this.listLoading = false;
					}
				});
			},
			
            //显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm.name = row.name;
				this.editForm.address = row.address;
				this.editForm.phone = row.phone;
				this.editForm.remarks = row.remarks;
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							let para = {
								name:this.editForm.name,
								address:this.editForm.address,
								phone:this.editForm.phone,
								remarks:this.editForm.remarks,
							}
							var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','admin_five_palace_token':JSON.parse(sessionStorage.getItem('token'))},
							});  
							instance.post('admin/platform/manage/updReturnAdress', this.qs.stringify(para)).then(data => {
								
								let  res = data.data;
								if (res.code !== 0) {
									this.$message({
										message: res.msg,
										type: 'error'
									});
								} else {
									this.editLoading = false;
									this.$message({
										message: '提交成功',
										type: 'success'
									});
									this.$refs['editForm'].resetFields();
									this.editFormVisible = false;
									this.getUsers();
								}
							});
						});
					}
				});
			}
		},
		mounted() {
			this.getUsers();
		}
	}
</script>
<style scoped>
</style>